package com.authentication.center;

import com.authentication.center.common.LoadKey;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import tk.mybatis.spring.annotation.MapperScan;

/**
 * 开启 apollo、dubbo、nacos
 *
 * @author garvin
 */
@MapperScan({"com.garvin.sso.mapper"})
@SpringBootApplication
public class AuthenticationCenterApplication {

    public static void main(String[] args) {
        System.setProperty("ENV", "DEV");
        System.setProperty("apollo.configService", "http://localhost:8080");
        SpringApplication.run(AuthenticationCenterApplication.class, args);
    }

    @Bean
    public TokenStore tokenStore(JwtAccessTokenConverter jwtAccessTokenConverter) {
        return new JwtTokenStore(jwtAccessTokenConverter);
    }

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter(LoadKey loadKey) {
        JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();
        accessTokenConverter.setKeyPair(loadKey.getKeyPair());
        return accessTokenConverter;
    }

}
